package com.baizhi.service.impl;

import com.baizhi.dao.UserDAO;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import com.baizhi.util.MybatisUtil;

public class UserServiceImpl implements UserService {

    @Override
    public User login(String username, String password) {
        User user=null;

        try {
            UserDAO ud =(UserDAO) MybatisUtil.getMapper(UserDAO.class);
            user = ud.userLogin(username,password);

        }catch (Exception e){
            e.printStackTrace();
            MybatisUtil.rollback();
            throw new RuntimeException(e);
        }finally {
            MybatisUtil.close();
        }

        return user;
    }

    @Override
    public void register(User user) {

        try {
            UserDAO ud =(UserDAO) MybatisUtil.getMapper(UserDAO.class);
            ud.userRegister(user);
            MybatisUtil.commit();
            
        }catch (Exception e){
            e.printStackTrace();
            MybatisUtil.rollback();
            throw new RuntimeException(e);
        }
    }
}
